<?php

class StorePasswordForm extends AbstractForm {
	const NAME = 'store';

	public function process() {
		return KeyGenius::storePassword($this->getValue('token'), $this->getValue('domain'), $this->getValue('password')) ? 'Password stored!' : 'Invalid Yubikey OTP or domain!';
	}

	public function getTitle() {
		return 'Store password';
	}

	public function getDescription() {
		return 'Store a new password for a site so that you can use your YubiKey to log in to the site, easily and securely.';
	}

	public function configure() {
		$this->setWidgets(array(
			'domain'	=> new sfWidgetFormInput(),
			'password'	=> new sfWidgetFormInput(array('type' => 'password')),
			'verify_password' => new sfWidgetFormInput(array('type' => 'password')),
			'token'		=> new sfWidgetFormInput(),
		));

		$this->widgetSchema->setNameFormat(self::NAME.'[%s]');

		$this->setValidators(array(
			'domain'	=> new sfValidatorString(),
			'password'	=> new sfValidatorString(),
			'verify_password' => new sfValidatorString(),
			'token'		=> new sfValidatorRegex(array('pattern' => self::OTP_PATTERN)),
		));

		$this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password', '==', 'verify_password'));
	}
}

?>
